# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: farawayer <farwayer@gmail.com>
# Contributor: Tim Meusel <tim@bastelfreak.de>

_gemname='public_suffix'
pkgname="ruby-${_gemname}"
pkgver=5.0.0
pkgrel=1
pkgdesc='Domain name parser based on the Public Suffix List'
arch=('any')
url='https://simonecarletti.com/code/publicsuffix-ruby'
license=('MIT')
makedepends=('ruby-rake' 'ruby-bundler' 'ruby-yard' 'ruby-rdoc')
checkdepends=('ruby-minitest' 'ruby-mocha')
depends=('ruby')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/weppos/publicsuffix-ruby/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.gz")
options=("!emptydirs")
sha512sums=('5854fc292dae3bd41c02259142ad85bbf2044b7423f58f791f91cc5cb16aff31552ddbe649366504d8c8a5678cabb93c07911583c6d5409ee89ee750269963c5')

prepare() {
  cd "${srcdir}/publicsuffix-ruby-${pkgver}"

  sed --in-place 's|git ls-files|find|' "${_gemname}.gemspec"
  sed --in-place '/test_files/d' "${_gemname}.gemspec"
  sed --in-place '/rubocop/Id' Rakefile
  sed --in-place '/reporters/Id' test/test_helper.rb
}

build() {
  cd "${srcdir}/publicsuffix-ruby-${pkgver}"
  gem build "${_gemname}.gemspec"
}

check() {
  cd "${srcdir}/publicsuffix-ruby-${pkgver}"
  rake test
}

package() {
  cd "${srcdir}/publicsuffix-ruby-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --verbose --ignore-dependencies --no-user-install --install-dir "${pkgdir}/${_gemdir}" --bindir "${pkgdir}/usr/bin" "${_gemname}-${pkgver}.gem"

  install -Dm 644 LICENSE.txt -t "${pkgdir}/usr/share/licenses/${pkgname}/"
  install -Dm 644 README.md SECURITY.md CHANGELOG.md 2.0-Upgrade.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/cache"
}

# vim: ts=2 sw=2 et:
